package com.lxl.mayi;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * @Author lixilin
 * @Date 2022/1/1 12:06
 * @Description 分组排序, 在进入reduce前进行分组排序
 */
public class UserIdOrderGroupingComparator extends WritableComparator {
    protected UserIdOrderGroupingComparator() {
        super(UserCarbon.class, true);
    }

    /**
     * 在进入reducer 方法之前进行 分组,让相同userid的数据进入一个reducer方法
     * @param a
     * @param b
     * @return
     */
    @Override
    public int compare(WritableComparable a, WritableComparable b) {

        // 根据userid进行group
        UserCarbon userA = (UserCarbon) a,
                   userB = (UserCarbon) b;
        return userA.getUserId().compareTo(userB.getUserId());
    }
}
